//
// Created by aaa on 2025/7/11.
//

#include<bits/stdc++.h>
const int N = 1e5 + 10;

using namespace std;
int n, k;
int a[N],s[N],q[N];

// 连续子序列的最大和
// 7 3
// 2 -3 5 2 -4 -1 8
int main(){
    cin >> n >> k;
    for(int i = 1;i <= n;i++) {
        cin >> a[i];
        s[i] = s[i - 1] + a[i];
    }

    int h = 0, t = 0;
    int ans = s[1];
    for(int i = 1;i <= n;i++){
        if(h <= t && q[h] < i - k) h++;
        ans = max(ans, s[i] - s[q[h]]);
        while(h <= t && s[i] <= s[q[t]]) t--;
        q[++t] = i;
    }

    cout << ans;


    return 0;
}